
from WtfEngine import *;
from scripts.widgets.TreeView import *;
from scripts.widgets.CheckBox import *;

gFont = WtfGui.Font("v_wtfEdit_ui_font");

class DataView(TreeView):
	def __init__(self):
		TreeView.__init__(self, "Data", gFont);
		self.RefreshAll();
	
	def RefreshAll(self):
		self.Clear();
		map(lambda obj: self.AddChild(Object(obj.data())), DataManager.GetInst().objects);
	

class Object(TreeView):
	def __init__(self, obj):
		TreeView.__init__(self, str(obj.name), gFont);
		
		#Enumerate parameters
		for n in dir(obj):
			v = getattr(obj,n);
			if not n.startswith("_") and not callable(v):
				self.AddChild(Member(n, v, gFont));
		
		self.Hide();
				
class EditString(WtfGui.LayoutContainer):
	def __init__(self, n, s, font = gFont):
		WtfGui.LayoutContainer.__init__(self,
			WtfGui.LayoutContainerCreationOptions(), 0);
		
		self.input = WtfGui.InputField(font);
		self.input.text = s;
		self.input.innerSize = iVector2D(60,12);
		
		self.AddChild(WtfGui.Label(n, font));
		self.AddChild(self.input);

class EditVector(TreeView):
	def __init__(self, n, v, font = gFont):
		TreeView.__init__(self, n, font);
		
		self.x = EditString("X", str(v.x), font);
		self.y = EditString("Y", str(v.y), font);
		self.z = EditString("Z", str(v.z), font);
		
		self.AddChild(self.x);
		self.AddChild(self.y);
		self.AddChild(self.z);
		
		
def Member(n, obj, font):
	if type(obj) == str:
		return EditString(n, obj);
	elif type(obj) == int:
		return EditString(n, str(obj));
	elif type(obj) == float:
		return EditString(n, str(obj));
	elif type(obj) == bool:
		return CheckBox(n, obj, font);
	elif type(obj) == Vector:
		return EditVector(n, obj, font);
	else:
		return TreeView(n, font);
